﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;

namespace SQLTouch.Service.DataContracts
{
    [DataContract]
    public class TableData
    {
        [DataMember]
        private readonly TableNameData name;
        [DataMember]
        private readonly List<ColumnData> columns;
        private ReadOnlyCollection<ColumnData> columnsReadOnly;

        private TableData()
        {

        }

        public TableData(TableNameData name, IEnumerable<ColumnData> columns)
        {
            this.name = name;
            this.columns = columns.ToList();
        }

        public TableNameData Name
        {
            get { return name; }
        }

        public ReadOnlyCollection<ColumnData> Columns
        {
            get
            {
                if (columnsReadOnly == null)
                {
                    columnsReadOnly = new ReadOnlyCollection<ColumnData>(columns);
                }
                return columnsReadOnly;
            }
        }
    }
}
